#!/bin/bash

# chkconfig: 35 99 01
# description: TrueCL Request Daemon process
#     

prog="TrueCL Request Daemon"
RETVAL=0

start() {
    echo -n "Starting $prog: "
    cd /opt/truecl/etc
    . ./clenv.sh
    $TRUECL_CODE/bin/clreqd --verbose
    RETVAL=0
    return $RETVAL
}

stop() {
    echo -n "Stopping $prog: "
    cd /opt/truecl/etc
    . ./clenv.sh
    $TRUECL_CODE/bin/clreq abort
    RETVAL=0
    return $RETVAL
}

status() {
    local xx
    cd /opt/truecl/etc
    . ./clenv.sh
    xx=`$TRUECL_CODE/bin/clreq echo 2>/dev/null`
    if [[ -n "$xx" && -n "$(echo "$xx" | grep -v ERROR)" ]]
    then
        echo $"$prog is running"
	RETVAL=0
    else
        echo $"$prog is not running"
        RETVAL=3
    fi
    return $RETVAL
}

case "$1" in
  start)
	start
	;;
  stop)
	stop
	;;
  status)
        status
	;;
  restart)
	stop
	start
	;;
esac

